//
//  XPersonDataHeaderCell.m
//  Veer
//
//  Created by Veer on 17/11/14.
//  Copyright © 2017年 Veer. All rights reserved.
//

#import "XPersonDataHeaderCell.h"

#import "XSettingItemModel.h"


@interface XPersonDataHeaderCell()

@property (nonatomic, weak) UIImageView *accessoryImageView;
@property (nonatomic, weak) UIView *bottomLineView;

@end

@implementation XPersonDataHeaderCell

+ (instancetype)cellWith:(UITableView *)tableview
{
    static NSString *cellID = @"XPersonDataHeaderCell";
    
    XPersonDataHeaderCell *cell = [tableview dequeueReusableCellWithIdentifier:cellID];
    //YAYIPersoninfoCell *cell = [super cellWith:tablevie];
    
    if (nil == cell) {
        cell = [[XPersonDataHeaderCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    }
    
    return cell;
}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.accessoryType = UITableViewCellAccessoryNone;
        self.textLabel.font = VRFont(14);
        self.textLabel.textColor = RGB(25, 25, 25);
        
        [self setupSubview];
        
    }
    return self;
}

- (void)setupSubview
{
    //
    
    
    //
    UILabel *nameLbl = [[UILabel alloc] init];
    nameLbl.font = VRFont(17);
    nameLbl.textColor = RGB(51, 51, 51);
    [self.contentView addSubview:nameLbl];
    self.nameLbl = nameLbl;
    
//    UIImageView *accessoryImageView = [[UIImageView alloc] init];
//    accessoryImageView.image = [UIImage imageNamed:@"accessoryIcon"];
//    [self.contentView addSubview:accessoryImageView];
//    self.accessoryImageView = accessoryImageView;
    
    UIImageView *iconVw = [[UIImageView alloc] init];
    iconVw.contentMode = UIViewContentModeScaleAspectFill;
    iconVw.clipsToBounds = YES;
    iconVw.layer.cornerRadius = 18;
    [self.contentView addSubview:iconVw];
    self.iconVw = iconVw;
    
    UIView *bottomLineView = [[UIView alloc] init];
    bottomLineView.backgroundColor = RGB(228, 228, 228);
    [self.contentView addSubview:bottomLineView];
    self.bottomLineView = bottomLineView;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    // 设置frame
    [self.nameLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.centerY.mas_equalTo(self.contentView);
    }];
    
    [self.iconVw mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(self.contentView);
        make.right.mas_equalTo(-15);
        make.width.mas_equalTo(36);
        make.height.mas_equalTo(36);
    }];
    
    [self.accessoryImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.centerY.mas_equalTo(self.contentView);
        make.width.mas_equalTo(6);
        make.height.mas_equalTo(10);
    }];
    
    [self.bottomLineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(15);
        make.right.right.mas_equalTo(self.contentView);
        make.bottom.mas_equalTo(self.contentView);
        make.height.mas_equalTo(0.5);
    }];
}




- (void)setModel:(XSettingItemModel *)model
{
    //[super setItem:item];
    _model = model;
    
    self.textLabel.text = model.name;
    
    if (model.icon.length == 0) {
        self.iconVw.image = [UIImage imageNamed:@"def_avatar"];
    }else{
        
        NSString *path = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
        path = [path stringByAppendingFormat:@"/%@", model.icon];
        self.iconVw.image = [UIImage imageWithContentsOfFile:path];
    }
    
    
}


@end
